
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script>

<link rel="stylesheet" href="/opebs/css/bootstrap.min.css">
<link rel="stylesheet" href="/opebs/css/bootstrap-select.css">
<script src="/opebs/js/bootstrap.min.js"></script>
<script src="/opebs/js/bootstrap-select.js"></script>

<#include "/common/h-ui-base-css.html">
<#include "/common/validation-js.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/h-ui/js/H-ui.min.js"></script>
<#--<script type="text/javascript" src="/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去&ndash;&gt;-->
<body>
<article class="page-container">

	<form class="form form-horizontal" id="form-car-add">

        <table class="table table-border table-bordered table-bg">
            <tbody>
                <tr>
                    <td>
                        车牌号：
                        <input type="text" class="input-text" autocomplete="off"  placeholder="" id="carId" name="carId"  onblur="toUpper()" value="${carInfo.carId!}">
                    </td>
                    <td>
                        最大载重量(吨)：<input type="text" class="input-text" autocomplete="off"  placeholder="" id="careWeight" name="careWeight" value="${carInfo.careWeight!}">
                    </td>

                </tr>

                <tr>
                    <td>
                        轴数：<select class="select" id="axesNumber" name="axesNumber" size="1">
                            <option data-tokens="0">请选择</option>
                            <option data-tokens="2轴" <#if carInfo.axesNumber??><#if carInfo.axesNumber=='2轴'>selected</#if></#if>>2轴</option>
                            <option data-tokens="3轴" <#if carInfo.axesNumber??><#if carInfo.axesNumber=='3轴'>selected</#if></#if>>3轴</option>
                            <option data-tokens="4轴" <#if carInfo.axesNumber??><#if carInfo.axesNumber=='4轴'>selected</#if></#if>>4轴</option>
                            <option data-tokens="5轴" <#if carInfo.axesNumber??><#if carInfo.axesNumber=='5轴'>selected</#if></#if>>5轴</option>
                            <option data-tokens="6轴" <#if carInfo.axesNumber??><#if carInfo.axesNumber=='6轴'>selected</#if></#if>>6轴</option>
                        </select>
                    </td>
                    <td>
                        车型：<select  class="select"  id="carModel" name="carModel" size="1"  >
                        <#if carInfo.carModel??>
                            <option value="${carInfo.carModel!}">${carInfo.carModel!}</option>
                        </#if>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        承运单位：
                        <input type="text" class="input-text" autocomplete="off"  placeholder="" id="transportUnit" name="transportUnit" value="${carInfo.transportUnit!}">
                    </td>
                    <td>
                        司机：<input type="text" class="input-text" autocomplete="off"  placeholder="" id="driver" name="driver" value="${carInfo.driver!}">
                    </td>
                </tr>
                <tr>
                    <td>
                        驾驶证编号：<input type="text" class="input-text" autocomplete="off"  placeholder="" id="driverLicense" name="driverLicense" value="${carInfo.driverLicense!}">
                    </td>
                    <td>
                        行驶证号：<input type="text" class="input-text" autocomplete="off"  placeholder="" id="license" name="license"  value="${carInfo.license!}">
                    </td>
                </tr>
                <tr>
                    <td>
                        从业资格证：<input type="text" class="input-text" autocomplete="off"  placeholder="" id="certificate" name="certificate" value="${carInfo.certificate!}">
                    </td>
                    <td>
                        道路运输许可证：<input type="text" class="input-text" autocomplete="off"  placeholder="" id="transportpermit" name="transportpermit" value="${carInfo.transportpermit!}">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        选择承运单位
                        <select id="transportSelect" class="selectpicker form-control" data-live-search="true" onchange="selectOnChange(this)">
                            <option data-tokens="">请选择</option>
                            <#if units??>
                                <#list units as m>
                                    <option data-tokens="${m.value}">${m.name}</option>
                                </#list>
                            </#if>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                        <input class="btn btn-primary radius" id="clear" type="button" value="&nbsp;&nbsp;清空&nbsp;&nbsp;">
                        <input class="btn btn-primary radius" id="cancel" type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
                    </td>
                </tr>
            </tbody>
        </table>
	</form>
</article>

<script type="text/javascript">
    $('#clear').click(function () {
        $('#driver').val('');
        $('#driverLicense').val('');
        $('#license').val('');
        $('#certificate').val('');
        $('#transportpermit').val('');
        $('#axesNumber').val('');
        $('#carModel').val('');
        $('#transportUnit').val('');
        $('#careWeight').val('');

    })
</script>


<script type="text/javascript">
    $('#cancel').click(function () {
        window.parent.layer.closeAll();
    });
    function toUpper(){
        var carId = $('#carId').val();
        var newCarId = carId.toUpperCase();
        $("#carId").val(newCarId);
        $.ajax({
            url : '/car-check/'+newCarId,
            async: true,
            success: function(data){
                var code = data.code;

                if(code==1){
                    $('#driver').val(data.obj.driver);
                    $('#driverLicense').val(data.obj.driverLicense);
                    $('#license').val(data.obj.license);
                    $('#certificate').val(data.obj.certificate);
                    $('#transportpermit').val(data.obj.transportpermit);
                    $('#transportUnit').val(data.obj.transportUnit);

                    // $('#careWeight').val(data.obj.careWeight);
                    // $('#axesNumber').val(data.obj.axesNumber);
                    // $('#carModel').val(data.obj.carModel);
                }

            }
        })


    }
</script>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    $(function(){
        $("#form-car-add").validate({
            rules:{
                carId:{
                    required:true,
                },
                axesNumber:{
                    required:true,
                },
                carModel:{
                    required:true,
                },
                careWeight:{
                    required:true,
                    number:true
                }
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var carId = $('#carId').val();
                var reg = new RegExp("[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}");
                if(!reg.test(carId)){
                    layer.msg("车牌格式输入错误");
                    return false;
                }

                var axes = $('#axesNumber').val();
                var careWeight = $('#careWeight').val();
                if(axes=='4轴'&&parseFloat(careWeight)>40){
                    layer.msg("4轴车，最大载货量设置错误");
                    return false;
                }
                if(axes=='6轴'&&parseFloat(careWeight)<45){
                    layer.msg("6轴车，最大载货量设置错误");
                    return false;
                }

                $(form).ajaxSubmit({
                    type: 'post',
                    url: "/car-ins-upd-del/-2" ,
                    data :$("form-car-add").serialize(),
                    async:false,
                    success: function(data){
                        window.parent.$("#max").val(data);
                        var grossA = window.parent.$('#gross').val();
                        var tareA = window.parent.$('#tare').val();
                        var w ;
                        if(grossA==''&&tareA!=''){
                            w = tareA;
                        }
                        if(grossA!=''&&tareA==''){
                            w=grossA;
                        }
                        if(parseFloat(w)>parseFloat(data)){
                            init();
                            window.parent.$('#incollection').removeClass("disabled");
                            layer.msg("该车已经超载，不能计量", {icon: 1});
                            alert('该车已经超载，不能计量');
                        }else{
                            //先判断是否能保存
                            var supplier = window.parent.$('#supplierNameCode').val();
                            var customerName = window.parent.$('#customerNameCode').val();
                            var material = window.parent.$('#materialNameCode').val();
                            if(supplier!=''&&customerName!=''&&material!=''){
                                window.parent.$('#incollection').addClass("disabled");
                                window.parent.$('#save').removeClass("disabled");
                            }
                            var carId = $('#carId').val();
                            var sheng = carId.substring(0, 1);
                            var carNm = carId.substring(1);
                            window.parent.$('#main-plate-no-pre').val(sheng)
                            window.parent.$('#carId-f').val(carNm);
                            window.parent.$('#source').show();

                        }
                        window.parent.layer.closeAll();
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg('error!',{icon:1,time:1000});
                    }
                });
            }
        });
    });
</script>

<!-- 二级联动 -->
<script type="text/javascript">
    $("#axesNumber").change(function(){
        //清空二级和三级select的旧选项
        $("#carModel").empty();
        //获得一级select的值
        var axesNumber = $(this).val();
        var carModelURL = '/car-ax-model/'+axesNumber;
        //如果一级select的值为null，隐藏二、三级select,并返回
        if(axesNumber == ''){
            $("#carModel").fadeOut("slow");
            return;
        }
        //根据一级select的值，异步获取数据更新二级的选项
        $.ajax({
            type:'get',
            url:carModelURL,
            cache:false,
            dataType:'json',
            success:function(secondDatas){
                //遍历回传的数据添加到二级select
                $.each(secondDatas, function(key, secondData) {
                    var option = '<option value="'+secondData.value+'">'+secondData.name+'</option>';
                    $("#carModel").append(option)
                    var ax = secondData.axes;
                    if(ax=='2轴'){
                        $('#careWeight').val(18.0);
                    }else if(ax=='3轴'){
                        $('#careWeight').val(25.0);
                    }else if(ax=='4轴'){
                        $('#careWeight').val(31.0);
                    }else if(ax=='5轴'){
                        $('#careWeight').val(0);
                    }else if(ax=='6轴'){
                        $('#careWeight').val(49);
                    }else{
                        $('#careWeight').val(0);
                    }
                })
                //二级select展示
                $("#carModel").fadeIn("slow");
            },
            error:function(){
                alert("请求失败")
            }
        });
    });

</script>

<!--/请在上方写此页面业务相关的脚本-->
</body>

<script type="text/javascript">
    function init(){
        // window.parent.$('#customerNameCode').val('');
        // window.parent.$('#supplierNameCode').val('');
        // window.parent.$('#materialNameCode').val('');
        window.parent.$('#measureId').val('');
        window.parent.$('#gross').val('');
        window.parent.$('#grossTime').val('');
        window.parent.$('#tare').val('');
        window.parent.$('#tareTime').val('');
        window.parent.$('#suttle').val('');
        window.parent.$('#grossWeightP').val('');
        window.parent.$('#unloadSymbol').val('');
        window.parent.$('#closeSymbol').val('');
        window.parent.$('#returnSymbol').val('');
        window.parent.$('#remarks1').val('');
        window.parent.$('#supplierName').val('');
        window.parent.$('#customerName').val('');
        window.parent.$('#carId-f').val('');
        window.parent.$('#materialName').val('');
        window.parent.$('#sourceGross').val('');
        window.parent.$('#sourceTare').val('');
        window.parent.$('#sourceSuttle').val('');
        window.parent.$('#remark2').val('');
        window.parent.$('#tareP').val('');
        window.parent.$('#max').val('');
        window.parent.$('#unloadDate').val('');
        window.parent.$('#grossWeightSite').val('');
        window.parent.$('#tareSite').val('');
        window.parent.$('#storageName').val('');
    }
</script>

<script>
    function selectOnChange(obj){
        var value = obj.options[obj.selectedIndex].value;
        if(value=='请选择'){

        }else{
            var l = value.indexOf("|");
            var t = value.substring(0, l);
            $('#transportUnit').val(t);
        }

    }
</script>